package com.fr.report.io.core;

import com.fr.base.FRContext;
import com.fr.base.core.FT;
import com.fr.report.CellElement;
import com.fr.report.DefaultCellElement;
import com.fr.report.FineBook;
import com.fr.report.FloatElement;
import com.fr.report.PageInfo;
import com.fr.report.PageSet;
import com.fr.report.Report;
import com.fr.report.ReportHF;
import com.fr.report.ReportPage;
import com.fr.report.ReportPageAttr;
import com.fr.report.ReportSettings;
import com.fr.report.ResultWorkBook;
import com.fr.report.cellElement.CellPageAttr;
import com.fr.report.core.DynamicValueList;
import com.fr.report.core.ReportUtils;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class PageExcelExporterReport extends ExcelReport
{
  private Report sourceReport;
  private PageSet pageSet;
  private FT xArea;
  private FT yArea;
  private int[] maxXY;
  private FT pageInfo;
  private int pageOrder;
  private List floatList = null;
  private ReportPage[][] page_array;

  public PageExcelExporterReport(Report paramReport, PageSet paramPageSet, FT paramFT1, FT paramFT2, FT paramFT3, int[] paramArrayOfInt, int paramInt)
  {
    this.sourceReport = paramReport;
    this.pageSet = paramPageSet;
    this.xArea = paramFT1;
    this.yArea = paramFT2;
    this.maxXY = paramArrayOfInt;
    this.pageOrder = paramInt;
    this.pageInfo = paramFT3;
    init();
  }

  private void init()
  {
    this.page_array = new ReportPage[this.yArea.to - this.yArea.from][this.xArea.to - this.xArea.from];
    if (this.pageOrder == 0)
    {
      i = this.xArea.from;
      while (true)
      {
        if (i >= this.xArea.to)
          break label433;
        for (j = this.yArea.from; j < this.yArea.to; ++j)
        {
          this.page_array[(j - this.yArea.from)][(i - this.xArea.from)] = this.pageSet.getPage(j - 1 + (i - 1) * this.maxXY[1]);
          this.page_array[(j - this.yArea.from)][(i - this.xArea.from)].getPageInfo().setTotalPages(this.pageInfo.to);
          this.page_array[(j - this.yArea.from)][(i - this.xArea.from)].setCurrentPageNumber(this.page_array[(j - this.yArea.from)][(i - this.xArea.from)].getCurrentPageNumber() + this.pageInfo.from);
        }
        ++i;
      }
    }
    for (int i = this.yArea.from; i < this.yArea.to; ++i)
      for (j = this.xArea.from; j < this.xArea.to; ++j)
      {
        this.page_array[(i - this.yArea.from)][(j - this.xArea.from)] = this.pageSet.getPage(j - 1 + (i - 1) * this.maxXY[0]);
        this.page_array[(i - this.yArea.from)][(j - this.xArea.from)].getPageInfo().setTotalPages(this.pageInfo.to);
        this.page_array[(i - this.yArea.from)][(j - this.xArea.from)].setCurrentPageNumber(this.page_array[(i - this.yArea.from)][(j - this.xArea.from)].getCurrentPageNumber() + this.pageInfo.from);
      }
    label433: i = 0;
    int j = 0;
    for (int k = 0; k < this.page_array.length; ++k)
      i += this.page_array[k][0].getRowCount();
    for (k = 0; k < this.page_array[0].length; ++k)
      j += this.page_array[0][k].getColumnCount();
    this.columnWidthList = new DynamicValueList(19, i);
    this.rowHeightList = new DynamicValueList(19, j);
  }

  public int getColumnWidth(int paramInt)
  {
    return this.columnWidthList.get(paramInt);
  }

  public int getRowHeight(int paramInt)
  {
    return this.rowHeightList.get(paramInt);
  }

  public Iterator cellIterator()
  {
    return new PageExcelCellIterator(this, null);
  }

  public Iterator floatIterator()
  {
    return ((this.floatList == null) ? null : this.floatList.iterator());
  }

  public ReportHF getFooter(int paramInt)
  {
    return this.sourceReport.getFooter(paramInt);
  }

  public ReportHF getHeader(int paramInt)
  {
    return this.sourceReport.getHeader(paramInt);
  }

  public ReportPageAttr getReportPageAttr()
  {
    return this.sourceReport.getReportPageAttr();
  }

  public ReportSettings getReportSettings()
  {
    return ReportUtils.getReportSettings(this.sourceReport);
  }

  public ResultWorkBook getResultWorkBook()
  {
    return null;
  }

  public void setResultWorkBook(ResultWorkBook paramResultWorkBook)
  {
    throw new UnsupportedOperationException();
  }

  public FineBook getBook()
  {
    return null;
  }

  static List access$102(PageExcelExporterReport paramPageExcelExporterReport, List paramList)
  {
    return (paramPageExcelExporterReport.floatList = paramList);
  }

  static ReportPage[][] access$200(PageExcelExporterReport paramPageExcelExporterReport)
  {
    return paramPageExcelExporterReport.page_array;
  }

  static List access$100(PageExcelExporterReport paramPageExcelExporterReport)
  {
    return paramPageExcelExporterReport.floatList;
  }

  private class PageExcelCellIterator
    implements Iterator
  {
    private CellElement next;
    private Iterator current_it;
    private int current_page_y;
    private int current_page_x;
    private int current_row;
    private Point current_offset;
    private boolean[] x_checklast;
    private final PageExcelExporterReport this$0;

    private PageExcelCellIterator()
    {
      this.this$0 = paramPageExcelExporterReport;
      PageExcelExporterReport.access$102(paramPageExcelExporterReport, new ArrayList());
      this.current_offset = new Point(0, 0);
      this.x_checklast = new boolean[PageExcelExporterReport.access$200(paramPageExcelExporterReport)[0].length];
      findNext();
    }

    public boolean hasNext()
    {
      return (this.next != null);
    }

    public Object next()
    {
      if (!(hasNext()))
        throw new NoSuchElementException("At last element");
      CellElement localCellElement = this.next;
      findNext();
      return localCellElement;
    }

    private void findNext()
    {
      while (this.current_page_y < PageExcelExporterReport.access$200(this.this$0).length)
      {
        while (this.current_row < PageExcelExporterReport.access$200(this.this$0)[this.current_page_y][0].getRowCount())
        {
          while (this.current_page_x < PageExcelExporterReport.access$200(this.this$0)[0].length)
          {
            Object localObject;
            if (this.current_it == null)
            {
              int i;
              this.current_it = PageExcelExporterReport.access$200(this.this$0)[this.current_page_y][this.current_page_x].getRow(this.current_row);
              if ((this.current_page_y == 0) && (this.current_row == 0))
                for (i = 0; i < PageExcelExporterReport.access$200(this.this$0)[this.current_page_y][this.current_page_x].getColumnCount(); ++i)
                  this.this$0.columnWidthList.set(this.current_offset.x + i, PageExcelExporterReport.access$200(this.this$0)[this.current_page_y][this.current_page_x].getColumnWidth(i));
              if ((this.current_page_x == 0) && (this.current_row == 0))
                for (i = 0; i < PageExcelExporterReport.access$200(this.this$0)[this.current_page_y][this.current_page_x].getRowCount(); ++i)
                  this.this$0.rowHeightList.set(this.current_offset.y + i, PageExcelExporterReport.access$200(this.this$0)[this.current_page_y][this.current_page_x].getRowHeight(i));
              if (this.current_row == 0)
              {
                localObject = PageExcelExporterReport.access$200(this.this$0)[this.current_page_y][this.current_page_x].floatIterator();
                while (((Iterator)localObject).hasNext())
                {
                  FloatElement localFloatElement = (FloatElement)((Iterator)localObject).next();
                  localFloatElement.setRow(localFloatElement.getRow() + this.current_offset.y);
                  localFloatElement.setColumn(localFloatElement.getColumn() + this.current_offset.x);
                  PageExcelExporterReport.access$100(this.this$0).add(localFloatElement);
                }
              }
            }
            if (this.current_it.hasNext())
            {
              localObject = (CellElement)this.current_it.next();
              if ((((CellElement)localObject).getRow() + ((CellElement)localObject).getRowSpan() == PageExcelExporterReport.access$200(this.this$0)[this.current_page_y][this.current_page_x].getRowCount()) && (((CellElement)localObject).getColumn() + ((CellElement)localObject).getColumnSpan() == PageExcelExporterReport.access$200(this.this$0)[this.current_page_y][this.current_page_x].getColumnCount()))
              {
                if (((CellElement)localObject).getCellPageAttr() != null)
                  try
                  {
                    ((CellElement)localObject).setCellPageAttr((CellPageAttr)((CellElement)localObject).getCellPageAttr().clone());
                  }
                  catch (CloneNotSupportedException localCloneNotSupportedException)
                  {
                    FRContext.getLogger().log(Level.WARNING, localCloneNotSupportedException.getMessage(), localCloneNotSupportedException);
                  }
                else
                  ((CellElement)localObject).setCellPageAttr(new CellPageAttr());
                if ((this.current_page_x == PageExcelExporterReport.access$200(this.this$0)[0].length - 1) && (this.current_page_y == PageExcelExporterReport.access$200(this.this$0).length - 1))
                  break label638:
                if (this.current_page_x == PageExcelExporterReport.access$200(this.this$0)[0].length - 1)
                {
                  ((CellElement)localObject).getCellPageAttr().setPageAfterRow(true);
                }
                else if (this.current_page_y == PageExcelExporterReport.access$200(this.this$0).length - 1)
                {
                  ((CellElement)localObject).getCellPageAttr().setPageAfterColumn(true);
                }
                else
                {
                  ((CellElement)localObject).getCellPageAttr().setPageAfterRow(true);
                  ((CellElement)localObject).getCellPageAttr().setPageAfterColumn(true);
                }
                label638: this.x_checklast[this.current_page_x] = true;
              }
              ((CellElement)localObject).setRow(((CellElement)localObject).getRow() + this.current_offset.y);
              ((CellElement)localObject).setColumn(((CellElement)localObject).getColumn() + this.current_offset.x);
              this.next = ((CellElement)localObject);
              return;
            }
            if ((this.current_row == PageExcelExporterReport.access$200(this.this$0)[this.current_page_y][0].getRowCount() - 1) && (this.x_checklast[this.current_page_x] == 0))
            {
              localObject = new DefaultCellElement();
              ((CellElement)localObject).setRow(this.current_offset.y + PageExcelExporterReport.access$200(this.this$0)[this.current_page_y][this.current_page_x].getRowCount() - 1);
              ((CellElement)localObject).setColumn(this.current_offset.x + PageExcelExporterReport.access$200(this.this$0)[this.current_page_y][this.current_page_x].getColumnCount() - 1);
              ((CellElement)localObject).setCellPageAttr(new CellPageAttr());
              if ((this.current_page_x == PageExcelExporterReport.access$200(this.this$0)[0].length - 1) && (this.current_page_y == PageExcelExporterReport.access$200(this.this$0).length - 1))
                break label946:
              if (this.current_page_x == PageExcelExporterReport.access$200(this.this$0)[0].length - 1)
              {
                ((CellElement)localObject).getCellPageAttr().setPageAfterRow(true);
              }
              else if (this.current_page_y == PageExcelExporterReport.access$200(this.this$0).length - 1)
              {
                ((CellElement)localObject).getCellPageAttr().setPageAfterColumn(true);
              }
              else
              {
                ((CellElement)localObject).getCellPageAttr().setPageAfterRow(true);
                ((CellElement)localObject).getCellPageAttr().setPageAfterColumn(true);
              }
              label946: this.x_checklast[this.current_page_x] = true;
              this.next = ((CellElement)localObject);
              return;
            }
            this.current_it = null;
            this.current_offset.x += PageExcelExporterReport.access$200(this.this$0)[this.current_page_y][this.current_page_x].getColumnCount();
            this.current_page_x += 1;
          }
          this.current_page_x = 0;
          this.current_offset.x = 0;
          this.current_row += 1;
        }
        for (int j = 0; j < this.x_checklast.length; ++j)
          this.x_checklast[j] = false;
        this.current_offset.y += this.current_row;
        this.current_row = 0;
        this.current_page_y += 1;
      }
      this.next = null;
    }

    public void remove()
    {
      throw new UnsupportedOperationException();
    }

    PageExcelCellIterator(, PageExcelExporterReport.1 param1)
    {
      this(paramPageExcelExporterReport);
    }
  }
}